import { Directive, Output, EventEmitter, Renderer2, ElementRef } from '@angular/core';

@Directive({
    selector: '[mousemove.stop]'
})
export class MouseMoveStopDirective {
    @Output("mousemove.stop") stopPropEvent = new EventEmitter();
    unsubscribe: () => void;

    constructor(
        private renderer: Renderer2,
        private element: ElementRef) {
    }

    ngOnInit() {
        this.unsubscribe = this.renderer.listen(
            this.element.nativeElement, 'mousemove', event => {
                event.stopPropagation();
                this.stopPropEvent.emit(event);
            });
    }

    ngOnDestroy() {
        this.unsubscribe();
    }
}